package com.coolingme.springframework.aop.aspect;

import com.coolingme.springframework.aop.intercept.MeMethodInterceptor;
import com.coolingme.springframework.aop.intercept.MeMethodInvocation;

import java.lang.reflect.Method;

/**
 * @author wangyue
 * @date 2024/09/10 22:19
 */
public class MeAfterReturningAdviceInterceptor extends MeAbstractAspectJAdvice implements MeMethodInterceptor {

    private MeJoinPoint jp;

    public MeAfterReturningAdviceInterceptor(Object aspect, Method adviceMethod) {
        super(aspect, adviceMethod);
    }


    private void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
        this.invokeAdviceMethod(this.jp, returnValue, null);
    }

    @Override
    public Object invoke(MeMethodInvocation mi) throws Throwable {
        jp = mi;
        Object retVal = mi.proceed();
        this.afterReturning(retVal, mi.getMethod(), mi.getArguments(), mi.getThis());
        return retVal;
    }
}
